package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.Message;
import com.ruoyi.wechat.domain.ScenicSpots;
import com.ruoyi.wechat.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.ActivityMapper;
import com.ruoyi.wechat.domain.Activity;
import com.ruoyi.wechat.service.IActivityService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 营地活动Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-31
 */
@Service
public class ActivityServiceImpl implements IActivityService 
{
    @Autowired
    private ActivityMapper activityMapper;

    @Autowired
    private IMessageService messageService;

    /**
     * 查询营地活动
     * 
     * @param activityId 营地活动主键
     * @return 营地活动
     */
    @Override
    public Activity selectActivityByActivityId(String activityId)
    {
        return activityMapper.selectActivityByActivityId(activityId);
    }

    /**
     * 查询营地活动列表
     * 
     * @param activity 营地活动
     * @return 营地活动
     */
    @Override
    public List<Activity> selectActivityList(Activity activity)
    {
        return activityMapper.selectActivityList(activity);
    }

    /**
     * 新增营地活动
     * 
     * @param activity 营地活动
     * @return 结果
     */
    @Override
    public int insertActivity(Activity activity)
    {
        activity.setActivityId(IdUtils.randomUUID());
        return activityMapper.insertActivity(activity);
    }

    /**
     * 修改营地活动
     * 
     * @param activity 营地活动
     * @return 结果
     */
    @Override
    public int updateActivity(Activity activity)
    {
        return activityMapper.updateActivity(activity);
    }

    /**
     * 批量删除营地活动
     * 
     * @param activityIds 需要删除的营地活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityByActivityIds(String[] activityIds)
    {
        return activityMapper.deleteActivityByActivityIds(activityIds);
    }

    /**
     * 删除营地活动信息
     * 
     * @param activityId 营地活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityByActivityId(String activityId)
    {
        return activityMapper.deleteActivityByActivityId(activityId);
    }

    /**
     * 审核活动并发送消息
     * @param activityId 活动Id
     * @param approve 审核状态
     * @param content 审核内容
     * @return 结果
     */
    @Transactional
    @Override
    public int approve(String activityId, String approve, String content) {
        //营地活动条件对象
        Activity activity = new Activity();
        activity.setActivityId(activityId);
        activity.setApprove(approve);
        //更新审核条件
        int rows = activityMapper.updateActivity(activity);
        //根据活动Id查询对象
        Activity activity1 = activityMapper.selectActivityByActivityId(activityId);
        //封装消息对象
        Message message = new Message();
        message.setCampId(activity1.getCampId());
        message.setContent(content);
        //调用消息
        int row = messageService.insertMessageByApprove(message,"4", approve, activity1.getActivityName());

        return rows;
    }
}
